﻿<!DOCTYPE html>
<%@ page language="java" import="com.newcrm.config.Const,com.newcrm.bean.*,com.newcrm.util.*,java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
  CustomerInfo customerInfo = (CustomerInfo)request.getAttribute("customerInfo");
  if (customerInfo == null) {
    request.getRequestDispatcher("/mobileV2/customerDetail-404.jsp").forward(request, response);
    return;
  }
  List<Map<String, Object>> fields = (List<Map<String, Object>>) request.getAttribute("fields");
  List<Map<String, Object>> peoples = (List<Map<String, Object>>)request.getAttribute("peoples");
  StringBuffer customerIds = new StringBuffer();
  customerIds.append(customerInfo.id);
  if (peoples != null) {
    for (Map<String, Object> p:peoples) {
      customerIds.append(",").append(p.get("CustomerId"));
    }
  }

  User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<Map<String, Object>> customerCategorys = companyInfo.customerCategorys;
  List<User> users = companyInfo.users;
  List<Map<String, Object>> tags = companyInfo.tags;

  List<Tag> companyTags = customerInfo.tags;
  int categoryId = customerInfo.categoryId;
  String categoryName = "";
  if (categoryId > 0) {
    for (Map<String, Object> item:customerCategorys) {
      if (categoryId == (Integer)item.get("CategoryId")) {
        categoryName = (String) item.get("CategoryName");
        break;
      }
    }
  }

  String customerPermissionInfo = "";
  if (customerInfo.visible == Const.VISIBLE_EVERYONE) {
    customerPermissionInfo = "公共客户";
  } else {
    for (User u:users) {
      if (u.userId.equals(customerInfo.permissionsId)) {
        customerPermissionInfo = u.name;
        break;
      }
    }
  }
  String iconStyle = "company";
  if (customerInfo.type == Const.TYPE_PEOPLE) {
    iconStyle = "person";
  }
%>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>企客宝</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/mobileV2/css/iconfont.css?ver=<%=Const.VERSION%>">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/mobileV2/css/sm.css?ver=<%=Const.VERSION%>">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/mobileV2/css/sm-extend.min.css?ver=<%=Const.VERSION%>">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/mobileV2/css/mobile.css?ver=<%=Const.VERSION%>">

    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/zepto.min.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/sm.min.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/sm-extend.min.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/mobile.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <jsp:include page="mobileCommonJS.jsp" flush="true"/>
  </head>
  <body>
    <div class="page-group">
      <div class="page" id="page-customerDetail">
        <input type="hidden" id="customerIds" value="<%=customerIds.toString()%>">
        <input type="hidden" id="customerParentId" value="<%=customerInfo.parentId%>">
        <input type="hidden" id="customerId" value="<%=customerInfo.id%>">
        <input type="hidden" id="customerType" value="<%=customerInfo.type%>">
        <input type="hidden" id="customerName" value="<%=Util.HTMLEncode(customerInfo.name)%>">
        <header class="bar bar-nav">
          <a class="button button-link button-nav pull-left back" id="link-note-back" href="#">
            <span class="icon iconfont icon-left"></span>
          </a>
          <h1 class='title'>客户详细</h1>
        </header>
        <div class="content">

          <div class="content-padded">
            <div class="customer-title">
              <i class="icon iconfont icon-<%=iconStyle%>"></i>
              <div class="customer-title-name">
                <span><%=Util.HTMLEncode(customerInfo.name)%></span>
                <% if (companyTags != null && companyTags.size() > 0) { %>
                <div class="tags" id="customerTags">
                <%  for (Tag tag:companyTags) { %>
                <span class="tag"><%=Util.HTMLEncode(tag.getName())%></span>
                <%  }%>
                </div>
                <% } %>
              </div>
            </div>
          </div>

          <div class="buttons-tab margin-top-20">
            <a href="#tab1" class="tab-link active button">联系记录</a>
            <a href="#tab2" class="tab-link button">基本信息</a>
            <% if (customerInfo.type == Const.TYPE_COMPANY) {%>
            <a href="#tab3" class="tab-link button">联系人</a>
            <%}%>
          </div>

          <div class="content-block">
            <div class="tabs">
              <div id="tab1" class="tab active">
                <div class="content-block">
                  <p>
                    <a href="#" id="link-add-note" class="button button-success button-big button-fill">添加备注</a>
                  </p>
                </div>
                <div class="content-block no-padding" id="customer-note-list"></div>
              </div>
              <div id="tab2" class="tab">
                <div class="list-block smallfont">
                  <ul>
                    <li class="item-content item-link" id="customer-category-container">
                      <div class="item-inner">
                        <div class="item-title">客户类型</div>
                        <div class="item-after"><%=Util.HTMLEncode(categoryName)%></div>
                      </div>
                    </li>
                    <li class="item-content item-link" id="customer-tag-container">
                      <div class="item-inner">
                        <div class="item-title">客户标签</div>
                        <div class="item-after">
                          <%
                          String tagIds = "";
                          if (companyTags != null && companyTags.size() > 0) {
                              for (Tag tag:companyTags) {
                                tagIds = tagIds + "," + tag.getId();
                              %>
                          <span class="tag"><%=Util.HTMLEncode(tag.getName())%></span>
                          <%  }
                          }%>
                        </div>
                      </div>
                      <input type="hidden" id="customerTagIds" value="<%=tagIds%>">
                    </li>
                    <li class="item-content">
                      <div class="item-inner">
                        <div class="item-title">客户所属</div>
                        <div class="item-after"><%=Util.HTMLEncode(customerPermissionInfo)%></div>
                      </div>
                    </li>
                    <li class="item-content">
                      <div class="item-inner">
                        <div class="item-title">创建时间</div>
                        <div class="item-after"><%=Util.HTMLEncode(customerInfo.createDate)%></div>
                      </div>
                    </li>
                    <li class="item-content">
                      <div class="item-inner">
                        <div class="item-title">分配时间</div>
                        <div class="item-after"><%=Util.HTMLEncode(customerInfo.assignDate)%></div>
                      </div>
                    </li>
                  </ul>
                </div>

                <div class="list-block smallfont">
                  <ul>
                    <%
                    List<ExtInfo> extInfos = customerInfo.extInfos;
                    for (ExtInfo extInfo : extInfos) {
                      if (extInfo.info1 == null || extInfo.info1.trim().length() == 0) {
                        continue;
                      }
                    %>
                    <li class="item-content">
                      <div class="item-inner">
                    <%
                      if (Const.CUSTOMER_EXT_INFO_TYPE_EMAIL == extInfo.type) { %>
                        <div class="item-title">邮箱</div>
                        <div class="item-after"><%=Util.HTMLEncode(extInfo.info1)%></div>
                      </div>
                    </li>
                    <%
                        continue;
                      }
                      if (Const.CUSTOMER_EXT_INFO_TYPE_PHONE == extInfo.type) { %>
                        <div class="item-title">电话</div>
                        <div class="item-after"><a href="tel:<%=Util.HTMLEncode(extInfo.info1)%>"><%=Util.HTMLEncode(extInfo.info1)%></a></div>
                      </div>
                    </li>
                    <%
                        continue;
                      }
                      if (Const.CUSTOMER_EXT_INFO_TYPE_WEBSITE == extInfo.type) { %>
                        <div class="item-title">网址</div>
                        <div class="item-after"><%=Util.HTMLEncode(extInfo.info1)%></div>
                      </div>
                    </li>
                    <%
                        continue;
                      }
                      if (Const.CUSTOMER_EXT_INFO_TYPE_ADDRESS == extInfo.type) { %>
                        <div class="item-title">地址</div>
                        <div class="item-after"><%=Util.HTMLEncode(extInfo.info1)%> <%=extInfo.info3%> <%=extInfo.info4%></div>
                      </div>
                    </li>
                    <%
                        continue;
                      }
                      if (Const.CUSTOMER_EXT_INFO_TYPE_IM == extInfo.type) { %>
                        <div class="item-title"><%=extInfo.info3%></div>
                        <div class="item-after"><%=Util.HTMLEncode(extInfo.info1)%></div>
                      </div>
                    </li>
                    <%
                        continue;
                      }
                    %>
                        <div class="item-title"><%=Util.getFieldName(extInfo.type, fields)%></div>
                        <div class="item-after"><%=Util.HTMLEncode(extInfo.info1)%></div>
                      </div>
                    </li>
                    <%}%>
                  </ul>
                </div>
              </div>
              <% if (customerInfo.type == Const.TYPE_COMPANY) {%>
              <div id="tab3" class="tab">
                <div class="list-block smallfont">
                  <ul>
                <% for (Map<String, Object> people : peoples) { %>
                <a href="<%=request.getContextPath()%>/m/customer?id=<%=people.get("CustomerId")%>">
                    <li class="item-content item-link">
                      <div class="item-media"><i class="icon icon-f7"></i></div>
                      <div class="item-inner">
                        <div class="item-title"><%=Util.HTMLEncode((String)people.get("Name"))%></div>
                        <div class="item-after"><%=Util.HTMLEncode((String)people.get("Title"))%></div>
                      </div>
                    </li>
                    </a>
                <%}%>
                  </ul>
                </div>
              </div>
              <%}%>
            </div>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-new-note">
        <div class="content-block">
          <p class="text-center">添加备注</p>
          <div class="list-block">
            <textarea id="note-remark" placeholder="添加备注"></textarea>
          </div>
          <div class="content-block">
            <div class="row">
              <div class="col-50"><a href="#" class="close-popup button button-big button-fill button-danger">取消</a></div>
              <div class="col-50"><a href="#" id="link-update-note" class="button button-big button-fill button-success">确定</a></div>
            </div>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-customer-change-category" >
        <div class="content-block">
          <p class="text-center">请选择客户分类</p>
          <div class="list-block">
            <ul id="customer-change-category-list">
              <li v="0" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >无分类</div>
                  </div>
                </div>
              </li>
<% if (customerCategorys != null) {
    for (Map<String, Object> category:customerCategorys) {%>
              <li v="<%=category.get("CategoryId") %>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" ><%=Util.HTMLEncode((String)category.get("CategoryName"))%></div>
                  </div>
                </div>
              </li>
<%
    }
  } %>
            </ul>
          </div>
          <div class="content-block">
            <p><a href="#" class="close-popup button button-big button-fill button-danger">取消</a></p>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-customer-change-tag" >
        <div class="content-block">
          <p class="text-center">请选择客户标签</p>
          <div class="list-block">
            <ul id="customer-change-tag-list">
<% if (tags != null) {
    for (Map<String, Object> tag:tags) {%>
              <li v="<%=tag.get("TagId") %>">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" ><%=Util.HTMLEncode((String)tag.get("TagName"))%></div>
                    <div class="item-after"></div>
                  </div>
                </div>
              </li>
<%
    }
  } %>
            </ul>
          </div>
          <div class="content-block">
            <div class="row">
              <div class="col-50"><a href="#" class="close-popup button button-big button-fill button-danger">取消</a></div>
              <div class="col-50"><a href="#" id="link-update-tag" class="button button-big button-fill button-success">确定</a></div>
            </div>
          </div>
        </div>
      </div>


    </div>
  </body>
</html>